<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>卡车上的最大单元数</title>
</head>
<body>
  <script>
    function fn(box, tru) {
      let arr = box.sort((a, b) => b[1] - a[1]), sum = 0
      for (let item of arr) {
        let count = item[0]
        while (count && tru) {
          sum += item[1]
          count--
          tru--
        }
      }
      return sum
    }
    console.log(fn([[1, 3], [2, 2], [3, 1]], 4))
  </script>
</body>
</html>